<?php
/**
 *此页面用于让用户选择场地的类型
 */
$cs = Yii::app()->getClientScript();
$cs->registerCSSFile(Yii::app()->request->baseUrl . '/css/mobile/booking_find_1.css');
$cs->registerCSSFile(Yii::app()->request->baseUrl . '/css/mobile/booking_list.css');
/*获取微信的Control*/
$screen = Blyn::app()->getUIManager()->getCurrentScreen();
$wxControl = $screen->getChildControl('BUIWXControl_1');
/*生成返回链接*/
$data = array();
if(isset($nowCity)) {
    $data['nowCity'] = $nowCity;    //获取用户当前所选的的城市，用于返回时确定城市
}
$findUrl = $wxControl->getLinkUrl(array('name' => 'find','id' => 'booking_find_1'),$data);
$eventList = Blyn::app()->getActiveApp()->getEventList();   //获取场馆的列表（即功能列表）
$courtTypeList = Blyn::app()->getActiveApp()->getCourtTypeList();   //获取类型的列表
unset($courtTypeList['badminton_court']);   //删除掉羽毛球这种类型
/*不同场地类型的图标*/
$courtTypeIcons = array(
    'soccer_court_5' => Yii::app()->request->baseUrl . '/images/BWeSport/1.png',
    'soccer_court_7' => Yii::app()->request->baseUrl . '/images/BWeSport/2.png',
    'soccer_court_11' => Yii::app()->request->baseUrl . '/images/BWeSport/3.png',
);
/*拆分$findText到$findTextArr中*/
$findTextArr = array();
$itemData = explode(' ',$findText);
foreach ($itemData as $value) {
    $condition = explode('=',$value);
    $findTextArr[$condition[0]] = $condition[1];
}
$event = new BWEvent($findTextArr['eventId']); //根据$eventId获取当前的场馆
$eventName = $event->getName();
/*获取此场馆不同场地类型的可预订场地数量*/
$itemData = array(
    'city' => $findTextArr['city'],
    'eventId' => $findTextArr['eventId'],
    'bookingStatus' => 'available',
    //下面的两个条件非常重要：
    'bookingStartTime' => '<='.time(),
    'bookingEndTime' => '>='.time(),
    //only get item for current space
    'spaceId'=>  Blyn::app()->getActiveSpace()->getId()
);
$treeTable = new BTreeTable('BWInputValue');
$valueList = $treeTable->getValueList('courtType', array('itemData' => $itemData));
?>
<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no">
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1" media="(device-height: 568px)">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="full-screen" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<link href="style/index.css" rel="stylesheet">
<style>
    body {background-color: #EAEAEA;}
    li {list-style: none;}
    #header {width: 100%;height: 50px;background-color: #2BB2A3;}
    #header a {display: inline-block;margin-top: 8px;}
    #header span {display: inline-block;margin-top: 8px;color: white;font-size: 20px;}
    #content{width:100%;}
    #box{width:90%;height:70px;border-radius:5px;background-color:white;margin:20px auto;}
    #box_img{width:25%;height:70px;margin:7px 10px;float:left;}
    ul.box_text{height:70px;float:left;margin-top:10px;padding:0px;}
    ul.box_text li{color:#82BB6C;font-size:20px;letter-spacing:2px;font-family:"微软雅黑";line-height:25px;width:auto;}
    .book{display:inline-block;overflow:hidden;float:left;}
    .book span{width:auto;display:inline-block;overflow:hidden;float:left;font-size:12px;letter-spacing:0px;margin-top:5px;}
    .book span.number{color:red;}
    .book span.place{color:#A2A297;}
    .book span.like{color:#A2A297;margin-left:15px;}
</style>
<body>
    <header class="navbar">
        <div class="nav-wrap-left">
            <a class="react back" href="<?php echo $findUrl;?>"><i class="text-icon icon-back"></i></a>
        </div>
        <h1 class="nav-header">选择场馆</h1>
        <?php $wxControl->renderView('booking_navigation', array());?>
    </header>
    <div id="content">
        <?php
        foreach ($courtTypeList as $courtType => $courtTypeCh) {
            $typeUrl = $wxControl->getLinkUrl(array(
                'name' => $courtTypeCh,
                'id' => 'showAddBooking_1'), array(
                'backPage' => 'booking_list_by_timeSlot',
                'findText' => $findText.' courtType='.$courtType,
                'flagText' => $eventName.'('.$courtTypeCh.')',
                'nowCity' => $nowCity  //通常是省市拼音，如：china.chongqing
            ));?>
            <div id="box">
                <a href="<?php echo $typeUrl;?>">
                    <div id="box_img">
                        <img src="<?php echo $courtTypeIcons[$courtType]?>" width="55px" height="55px"/>
                    </div>
                    <ul class="box_text">
                        <li style="font-weight:bold"><?php echo $courtTypeCh;?></li>
                        <li>
                            <div class="book">
                                <span class="number">
                                    <?php
                                    /*输出某个场馆中各类型场地的数量*/
                                    if(isset($valueList[$courtType])) {
                                        echo $valueList[$courtType];
                                    } else{
                                        echo 0;
                                    }?>
                                    &nbsp;
                                </span>
                                <span class="place">个场地可预订</span>
                                <span class="like">喜欢 297</span>
                            </div>
                        </li>
                    </ul>
                </a>
            </div>      
        <?php }?>
    </div>
    <footer>
        <div class="footer-copyright">
            <div class="hr"></div>
            <span class="footer-copyright-text">
			Copyright © 2014 billyn.net </span>
        </div>
    </footer>
</body>
</html>